package com.lgx.common.web.tag;

import java.io.IOException;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;

import com.lgx.common.web.Constants;
import com.lgx.right.entity.Permission;

/**
 * 操作权限标签
 * 
 * @author acer
 *
 */
public class OperatePermissionTagSupport extends BodyTagSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4515370666218795399L;
	
	/**
	 * 权限ID
	 */
	public String permissionId;

	public String getPermissionId() {
		return permissionId;
	}

	public void setPermissionId(String permissionId) {
		this.permissionId = permissionId;
	}
	
	public int doEndTag() throws JspException {
		List<Permission> operates = Constants.operates;
		boolean flag = false;
		
		for(Permission p : operates)
		{
			if(permissionId.equals(p.getId()+""))
			{
				flag = true;
		        break;
			}
		}
		
		try {
			
			if(flag)
			{
				this.getBodyContent().writeOut(this.pageContext.getOut());
		        this.pageContext.getOut().flush();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		return EVAL_PAGE;
	}

}
